package com.lagou.sqlSession;

import com.lagou.config.XmlConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author: jie.zhao
 * @create: 2021/01/24 10:18
 */
public class SqlSessionFactoryBuilder {


    public SqlSessionFactory  buildSqlSessionFactory(InputStream inputStream) throws DocumentException, PropertyVetoException {
        // 解析配置文件，封装为Configuration对象
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);
        // 创建sqlSessionFactory
        return build(configuration);
    }

    public SqlSessionFactory build(Configuration configuration) {
        return new DefaultSqlSessionFactory(configuration);
    }



}
